﻿using System;
using System.Collections.Generic;
using System.Linq;
using UcAsp.Net.Model;
namespace UcAsp.Net.NOSQLDAL
{
    public class SysParamDAL : UcAsp.Net.IDAL.ISysParamDAL
    {
        public List<SysParam> GetSysParam()
        {
            return STSData.GetInstance.Select<Model.SysParam>();
        }
        public SysParam Insert(SysParam model)
        {
            long key;
            Model.SysParam lastrow = STSData.GetInstance.LastRow<Model.SysParam>(out key);
            model.ID = Convert.ToInt32(key.ToString()) + 1;
            STSData.GetInstance.Insert<Model.SysParam>(model.ID, model);
            return model;
        }
        public bool Update(SysParam model)
        {
            STSData.GetInstance.Update<Model.SysParam>(model.ID, model);
            return true;
        }
        public bool Delete(SysParam model)
        {
            STSData.GetInstance.Delete<Model.SysParam>(model.ID);
            return true;
        }
        public List<SysParam> GetListByGroupID(int id)
        {
            return GetSysParam().Where(o => o.GroupID == id).ToList();
        }
        public SysParam GetParamByName(string name)
        {
            return GetSysParam().FirstOrDefault(o => o.ParamName == name);
        }
        public SysParam GetParamByID(int id)
        {
            return GetSysParam().FirstOrDefault(o => o.ID == id);
        }
        public List<SysParam> Select(int pagesize, int pageindex, out int pagecount)
        {
            List<SysParam> list = new List<SysParam>();
            var query = GetSysParam();
            pagecount = (query.Count / pagesize) + 1;
            list = query.OrderBy(o => o.ID).Skip(pagesize * pageindex).Take(pagesize).ToList();
            return list;
        }
    }
}